<template>
  <el-dialog
    custom-class="z-dialog"
    :title="title"
    :visible.sync="dialogVisible"
    v-if="dialogVisible"
    :width="width"
    v-on="$listeners"
  >
    <slot>这是一段信息</slot>
    <template slot="footer">
      <slot name="footer">
        <z-button type="def" v-if="showCancelButton" @click="dialogVisible = false">{{
          cancelButtonText
        }}</z-button>
        <z-button
          v-if="showConfirmButton"
          :disabled="disabled || loading"
          :loading="loading"
          @click="onConfirm"
          >{{ confirmButtonText }}</z-button
        >
      </slot>
    </template>
  </el-dialog>
</template>

<script>
import ZButton from "./ZButton.vue";
export default {
  name: "ZModal",
  components: {
    ZButton,
  },
  props: {
    //标题
    title: {
      type: String,
      default: "标题",
    },
    //模态框是否可见
    visible: {
      type: Boolean,
      default: false,
    },
    //是否显示取消按钮
    showCancelButton: {
      type: Boolean,
      default: true,
    },
    //是否显示确定按钮
    showConfirmButton: {
      type: Boolean,
      default: true,
    },
    //取消按钮的文本内容
    cancelButtonText: {
      type: String,
      default: "取 消",
    },
    //确定按钮的文本内容
    confirmButtonText: {
      type: String,
      default: "确 定",
    },
    //确认按钮禁用
    disabled: {
      type: Boolean,
      default: false,
    },
    //确认按钮等待
    loading: {
      type: Boolean,
      default: false,
    },
    width: {
      type: String,
      default: "755px",
    },
  },
  data() {
    return {
      dialogVisible: false,
    };
  },
  watch: {
    visible(v) {
      this.dialogVisible = v;
    },
  },
  methods: {
    onConfirm() {
      this.$emit("onConfirm");
    },
  },
};
</script>

<style lang="scss">
.z-dialog {
  border-radius: 6px;
}
</style>
